package com.smile.stream.stream;

import com.smile.stream.StreamUtil;
import com.smile.stream.pojo.Dish;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/10/7 16:12
 */
public class StreamDemo1 {
    /**
     * 筛选卡路里大于300的菜品名
     * @param args
     */
    public static void main(String[] args) {
        List<Dish> menu = StreamUtil.getMenu();
        System.out.println(menu);
        List<String> names = menu
                .stream()
                .filter(v -> {
                    //打印当前筛选的菜肴
                    System.out.println("filtering >>" + v.getName());
                    return v.getCalories() > 300;
                }).map(v -> {
                    //提取菜名时打印出来
                    System.out.println("mapping >>" + v.getName());
                    return v.getName();
                }).limit(3).collect(Collectors.toList());
        System.out.println(names);
    }
}
